<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试结果 - ${score.examName}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        .result-card {
            max-width: 600px;
            margin: 40px auto;
            border-radius: 15px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
        }
        .result-header {
            background-color: #0d6efd;
            color: white;
            padding: 2rem;
            border-top-left-radius: 15px;
            border-top-right-radius: 15px;
            text-align: center;
        }
        .score-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: -50px;
        }
        .score-circle {
            width: 150px;
            height: 150px;
            border-radius: 50%;
            background-color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 3.5rem;
            font-weight: bold;
            border: 5px solid #0d6efd;
            z-index: 10;
        }
        .result-body {
            padding: 2rem;
            padding-top: 3rem;
        }
        .result-details li {
            border-bottom: 1px solid #eee;
            padding: 10px 0;
        }
        .result-details li:last-child {
            border-bottom: none;
        }
    </style>
</head>
<body>

<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container">
        <a class="navbar-brand" href="${pageContext.request.contextPath}/dashboard">
            <i class="fa fa-graduation-cap mr-2"></i>学生考试管理系统
        </a>
        <div class="navbar-nav">
            <a class="nav-link" href="${pageContext.request.contextPath}/exams">返回考试列表</a>
        </div>
    </div>
</nav>

<!-- 主内容 -->
<div class="container">
    <div class="card result-card">
        <div class="result-header">
            <h3>${score.exam.examName}</h3>
            <p class="lead">考试结果报告</p>
        </div>

        <div class="score-container">
            <div class="score-circle" id="score-display">${score.score}</div>
        </div>

        <div class="result-body text-center">
            <h4 class="mb-3">
                <c:choose>
                    <c:when test="${score.score >= 90}">
                        <i class="fa fa-trophy text-warning"></i> 成绩优秀！
                    </c:when>
                    <c:when test="${score.score >= 60}">
                        <i class="fa fa-check-circle text-success"></i> 恭喜，通过考试！
                    </c:when>
                    <c:otherwise>
                        <i class="fa fa-exclamation-triangle text-danger"></i> 加油，还需努力！
                    </c:otherwise>
                </c:choose>
            </h4>
            <p class="text-muted">
                ${score.studentName}，这是您本次的考试成绩。
            </p>

            <ul class="list-unstyled text-start mt-4 result-details">
                <li>
                    <strong><i class="fa fa-user"></i> 考生姓名:</strong>
                    <span class="float-end">${score.studentName}</span>
                </li>
                <li>
                    <strong><i class="fa fa-book"></i> 考试科目:</strong>
                    <span class="float-end">${score.exam.examName}</span>
                </li>
                <li>
                    <strong><i class="fa fa-calendar"></i> 提交时间:</strong>
                    <span class="float-end">
                        <c:if test="${not empty score.examTime}">
                            ${score.examTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))}
                        </c:if>
                    </span>
                </li>
                <li>
                    <strong><i class="fa fa-star"></i> 本次得分:</strong>
                    <span class="float-end fw-bold">${score.score} / 100</span>
                </li>
            </ul>

            <a href="${pageContext.request.contextPath}/exams" class="btn btn-primary mt-4">
                <i class="fa fa-arrow-left"></i> 返回考试列表
            </a>
        </div>
    </div>
</div>

<script>
    // 动态调整得分颜色
    const scoreValue = ${score.score};
    const scoreDisplay = document.getElementById('score-display');
    if (scoreValue >= 90) {
        scoreDisplay.style.color = '#ffc107'; // 黄色
        scoreDisplay.style.borderColor = '#ffc107';
    } else if (scoreValue >= 60) {
        scoreDisplay.style.color = '#198754'; // 绿色
        scoreDisplay.style.borderColor = '#198754';
    } else {
        scoreDisplay.style.color = '#dc3545'; // 红色
        scoreDisplay.style.borderColor = '#dc3545';
    }
</script>

</body>
</html>